import Vue from 'vue';
import Vuex from 'vuex';



Vue.use(Vuex);

let instate = {
  tokenInfo: {}
}
const stateStr = localStorage.getItem('state')

if(stateStr){
  instate = JSON.parse(stateStr)
}
export default new Vuex.Store({
  state: instate,
  mutations: {
    // 更新tokenInfo数据的方法
    updateTokenInfo(state,payload){
      // 把提交过来的payload对象，作为tokenInfo的值
      state.tokenInfo = payload
      // 测试state中是否有数据，打印state123
      console.log(state)
      this.commit('saveStateToStorage')
    },
    saveStateToStorage(state){
      localStorage.setItem('state',JSON.stringify(state))
    }
  },
  actions: {
  },
  modules: {
  },
});
